package com.auxide.util;

import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

import com.auxide.cah.MainActivity;

public class Logger {
	private static MainActivity myActivity;
	public static void setContext(MainActivity c){ myActivity = c; }
	public static final String TAG = "CAH";
	
	private static void queueMessage(String text){
		Message msg = MainActivity.handler.obtainMessage();
		msg.obj = text;
		MainActivity.handler.sendMessage(msg);
	}
	public static void popUp(String msg){
		if(Looper.getMainLooper().getThread() == Thread.currentThread()) {
			Toast.makeText(myActivity, msg, Toast.LENGTH_SHORT).show();
		}else{
			queueMessage(msg);
		}
	}
	
	
	public static void log(String msg){
		//if(prefs.getBoolean(OptionsActivity.LOG_KEY, OptionsActivity.LOG_KEY_DEF)){
			Log.d(TAG,msg);
		//}	
	}

	public static void log(String tag, String msg){
		//if(prefs.getBoolean(OptionsActivity.LOG_KEY, OptionsActivity.LOG_KEY_DEF)){
			Log.d(tag,msg);
		//}	
	}
	
	public static void e(Exception e){
		Log.e(TAG, e.toString(), e);
	}
}